package com.yao.mssm.system.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Service;

import com.yao.mssm.system.dao.EmpDao;
import com.yao.mssm.system.entity.Employee;
import com.yao.mssm.system.service.IEmpService;
import com.yao.mssm.system.service.support.BaseServiceImpl;


@Service
public class EmpService extends BaseServiceImpl<EmpDao,Employee> implements IEmpService{
	
	@Autowired
	private JmsTemplate jmsTemplate;

	@Override
	public List<Employee> selectTop5() {
		
		return baseMapper.selectTop5();
	}
	
	@Override
	public int insertEmp(Employee emp){
		
		jmsTemplate.send(new MessageCreator() {
			@Override
			public Message createMessage(Session session) throws JMSException {
				SimpleDateFormat f = new SimpleDateFormat("HH:mm:ss");
				TextMessage m = session.createTextMessage(f.format(new Date()));
				return m;
			}
		});
		
		return baseMapper.insert(emp);
	}

}
